"""
下拉列表控件
1.如何将列表项添加到控件中
2.如何获取选中的列表项
"""
import sys
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import *


class QComboxDemo(QWidget):
    def __init__(self):
        super(QComboxDemo, self).__init__()
        self.iniUI()

    def iniUI(self):
        self.setWindowTitle("复选框控件演示")
        self.resize(300, 225)

        self.layout = QHBoxLayout()
        self.label = QLabel('请选择编程语言')
        self.label.setFont(QFont("微软雅黑", 8))
        self.cb = QComboBox()
        self.cb.addItem('C++')
        self.cb.addItem("Python")
        self.cb.addItem("C#")
        self.cb.addItem("Java")
        self.cb.addItems(['PHP', 'Ruby', 'C'])

        self.cb.setFont(QFont('微软雅黑',10))
        self.layout.addWidget(self.cb)
        self.layout.addWidget(self.label)

        self.cb.currentIndexChanged.connect(self.selectionChange)

        self.setLayout(self.layout)

    def selectionChange(self, i):
        self.label.setText(str(i)+': ' +self.cb.currentText())
        self.label.adjustSize()
        for count in range(self.cb.count()):
            print(f'item{count} = '+self.cb.itemText(count))



if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = QComboxDemo()
    main.show()
    sys.exit(app.exec_())
